package com.dddd.blog.blogsp.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dddd.blog.blogcommon.pojo.Result;
import com.dddd.blog.blogsp.entity.Blog;
import com.dddd.blog.blogsp.feign.ForPostFeignClient;
import com.dddd.blog.blogsp.mapper.BlogContentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 喵星球的大橘
 */
@Service("blogContentService")
@Transactional(rollbackFor = Exception.class)
public class BlogContentServiceImpl extends ServiceImpl<BlogContentMapper, Blog> implements BlogContentService {

    @Autowired
    private ForPostFeignClient forPostFeignClient;

    @Resource
    private BlogContentMapper blogContentMapper;

    @Override
    public int addPost(Blog blog) {
        return blogContentMapper.addPost(blog);
    }

    @Override
    public int addPostRecords(Map<String,Blog> records) {
        return blogContentMapper.addPostList(records);
    }

    @Override
    public List<String> getAuthorList() {

        return null;
    }

    @Override
    public List<Map<String,Object>> getPostList(){

        List<Map<String, Object>> list = blogContentMapper.getPostList();
        return list;
    }

    @Override
    public int addPostByMap(Map<String,Object> post){

        Result result = forPostFeignClient.addPostByMap(post);
        return (Integer) result.getData();
    }
}
